const Koa = require('koa')
const Router = require('koa-router')
const static = require('koa-static')
const cors = require('koa2-cors')
const path = require('path')
const koaBody = require('koa-body')
const router = new Router()
const app = new Koa()

app.use(static(path.join(__dirname,'../pubilc')))
const mini = require('../route/mini_server/index.js')
const pc = require('../route/pc_server/index.js')
const { authMiddleware,accessLogger } = require('../utils/middleware')
console.log(__dirname)
app.use(koaBody({
	multipart:true,
	formidable:{
		maxFieldsSize:50*1024*1024,
		uploadDir:path.join(__dirname,'../pubilc/images'),
		keepExtensions:true
	}
}))
app.use(cors({origin:"*",methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS']}))
app.use(authMiddleware)
app.use(accessLogger)
router.use('/mini',mini.routes())
router.use('/pc',pc.routes())
app.use(router.routes())


module.exports = app